package org.lc.stk.web.dto.question;

import java.util.ArrayList;
import java.util.List;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;

@Schema(description = "填空题数据传输对象")
public class FillBlankQuestionDTO extends QuestionResponseDTO {
    
    @Schema(description = "题干富文本内容，使用{{n}}标记填空位置")
    @NotBlank(message = "题干不能为空")
    private String stemContent;
    
    @Schema(description = "答案列表")
    @NotNull(message = "答案列表不能为空")
    @Size(min = 1, message = "至少需要一个答案")
    private List<FillBlankAnswerDTO> answers = new ArrayList<>();
    
    @Schema(description = "答案是否可互换")
    private boolean answersInterchangeable;

    // 添加无参构造函数
    public FillBlankQuestionDTO() {
        super();
    }
    
    @Schema(description = "填空题答案")
    public static class FillBlankAnswerDTO {
        @Schema(description = "答案富文本内容")
        @NotBlank(message = "答案内容不能为空")
        private String content;
        
        @Schema(description = "填空位序号，从1开始")
        @NotNull(message = "填空位序号不能为空")
        private Integer blankIndex;
        
        public FillBlankAnswerDTO() {
        }

        public FillBlankAnswerDTO(String content, Integer blankIndex) {
            this.content = content;
            this.blankIndex = blankIndex;
        }

        // Getters and Setters
        public String getContent() {
            return content;
        }

        public void setContent(String content) {
            this.content = content;
        }

        public Integer getBlankIndex() {
            return blankIndex;
        }

        public void setBlankIndex(Integer blankIndex) {
            this.blankIndex = blankIndex;
        }
    }

    // Getters and Setters
    public String getStemContent() {
        return stemContent;
    }

    public void setStemContent(String stemContent) {
        this.stemContent = stemContent;
    }

    public List<FillBlankAnswerDTO> getAnswers() {
        return answers;
    }

    public void setAnswers(List<FillBlankAnswerDTO> answers) {
        this.answers = answers;
    }

    public void addAnswer(String content, Integer blankIndex) {
        this.answers.add(new FillBlankAnswerDTO(content, blankIndex));
    }

    public boolean isAnswersInterchangeable() {
        return answersInterchangeable;
    }

    public void setAnswersInterchangeable(boolean answersInterchangeable) {
        this.answersInterchangeable = answersInterchangeable;
    }
}